using System;
using System.Data;
using System.Xml;
using OR.Lazarus.Library;
using OR.Lazarus.Business;



namespace OR.Lazarus.Library.DataTier.Compiled
{
	public class ProjectDetail : OR.Lazarus.Library.DataTier.Compiled.Lazarus.ProjectDetail, IProject
	{
      private bool mUseParameterPrefix;

      public bool UseParameterPrefix
      {
         get { return mUseParameterPrefix; }
         set { mUseParameterPrefix = value; }
      }

      public override XmlElement SaveXml( XmlDocument p_docContext )
      {
         XmlElement vReturn = base.SaveXml( p_docContext );

         vReturn.SetAttribute( "B", mUseParameterPrefix.ToString() );

         return ( vReturn );
      }

      public FieldDetail FindFieldByObject( string p_szObjectName, string p_szFieldName )
		{
			ObjectDetail	v_oObject	= null;
			FieldDetail		v_oReturn	= null;

			v_oObject = this.Objects[ p_szObjectName ];

			if ( v_oObject == null )
			{
				throw new Exception( "Object [ " + p_szObjectName + " ] cannot be found." );
			}

			v_oReturn = v_oObject.Fields[ p_szFieldName ];

			if ( v_oReturn == null )
			{
				throw new Exception( "Field [ " + p_szObjectName + "." + p_szFieldName + " ] cannot be found." );
			}

			return ( v_oReturn );
		}

      #region IProject Members


      public string GetRelativePath( string pDelimiter, bool pShowPrefix, bool pShowSuffix )
      {
         string vReturn = String.Empty;
         bool vShowBusinessConcept  = !String.IsNullOrEmpty( this.BusinessConcept );
         bool vShowDefaultNamespace = !String.IsNullOrEmpty( this.DefaultNamespace );

         if ( pShowPrefix )                                    { vReturn += pDelimiter; }
         if ( vShowBusinessConcept )                           { vReturn += this.BusinessConcept; }
         if ( vShowBusinessConcept && vShowDefaultNamespace )  { vReturn += pDelimiter; }
         if ( vShowDefaultNamespace )                          { vReturn += this.DefaultNamespace; }
         if ( pShowSuffix )                                    { vReturn += pDelimiter; }

         return ( vReturn );
      }

      #endregion
   }
}
